<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "buyer_cashback".
 *
 * @property int $id
 * @property int $uid
 * @property int $buyer_id
 * @property int $auth_shop_id
 * @property int $auth_order_id
 * @property string|null $order_no
 * @property string|null $content
 * @property string|null $user_account
 * @property string|null $user_realname
 * @property int $return_fee 返现金额
 * @property int $ctime
 * @property int $state
 */
class BuyerCashback extends \yii\db\ActiveRecord
{
    const STATE_CHECKING = 1;
    const STATE_SUCCESS = 2;
    const STATE_FAIL = 3;
    static public $state_arr = [
        self::STATE_CHECKING =>'审核中',
        self::STATE_SUCCESS =>'审核成功',
        self::STATE_FAIL =>'审核失败',
    ];
    public function showState(){
        return self::$state_arr[$this->state]??'未知';
    }
    //关联
    public function getPics(){
        return $this->hasMany(BuyerCashbackPic::className(),['buyer_cashback_id'=>'id']);
    }
    //关联
    public function getAuthShop(){
        return $this->hasOne(AuthShop::className(),['id'=>'auth_shop_id']);
    }
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'buyer_cashback';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uid', 'buyer_id', 'auth_shop_id', 'auth_order_id', 'return_fee', 'ctime', 'state'], 'integer'],
            [['content'], 'string'],
            [['order_no', 'user_account', 'user_realname'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => 'Uid',
            'buyer_id' => 'Buyer ID',
            'auth_shop_id' => '店铺',
            'auth_order_id' => 'Auth Order ID',
            'order_no' => '订单号',
            'content' => '备注',
            'user_account' => '买家账号',
            'user_realname' => '买家姓名',
            'return_fee' => '返现金额',
            'ctime' => '创建时间',
            'state' => '状态',
        ];
    }
}
